<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/socket.io/2.1.1/socket.io.js"></script>

    <script type="text/javascript">
        // 此处userId为用户标识，后面推送时使用
        var socket = io.connect('http://127.0.0.1:8082?userId=1', {
            'reconnection delay' : 2000,
            'force new connection' : true
        });

        socket.on('message', function(data) {
            // here is your handler on messages from server
            console.log(data)
        });

        socket.on('chatevent', function(data) {
            // here is your handler on chatevent from server
            console.log(data)
        });

        socket.on('connect', function() {
            // connection established, now we can send an objects

            // send json-object to server
            // '@class' property should be defined and should
            // equals to full class name.
            var obj = { '@class' : 'com.sample.SomeClass'
            }
            socket.json.send(obj);

            // send event-object to server
            // '@class' property is NOT necessary in this case
            var event = {

            }
            socket.emit('someevent', event);

        });

    </script>
</head>
<body>

</body>
</html>